﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;


namespace Database
{

    [DataContract]
    public class User
    {
        [DataMember]
        private string uname;
        [DataMember]
        private string name;
        [DataMember]
        private string lastName;
        [DataMember]
        private string password;
        [DataMember]
        private string email;
        [DataMember]
        private SortedDictionary <string, User> friends;
        [DataMember]
        private DateTime creationTime;

        public User(string uname, string name, string lastName, string password, string email)
        {
            this.uname = uname;
            this.name = name;
            this.lastName = lastName;
            this.password = password;
            this.email = email;
            this.friends = new SortedDictionary <string, User>();
        }

        public void setPassword(string pass)
        {
            this.password = pass;
        }


        public string getUserName()
        {
            return this.uname;
        }

        public string getName() {
            return this.name;
        }

        public string getLastName() {
            return this.lastName;
        }

        public string getEmail() {
            return this.email;
        }

        public SortedDictionary <string, User> getFriends() {
            return this.friends;
        }

        public bool isFriend(User friend) {
            bool ans = false;
            if(friend != null) 
                ans = friends.ContainsKey(friend.getUserName());
            return ans;
        }

        public bool isFriend(string friendName)
        {
            bool ans = false;
            if (friendName != null)
                ans = friends.ContainsKey(friendName);
            return ans;
        }

        public bool addFriend(User newFriend) {
            bool ans = false;
            if (newFriend != null && friends.ContainsKey(newFriend.getUserName()) == false) {
                friends.Add(newFriend.getUserName(), newFriend);
                ans = true;
            }
            return ans;
        }

        public bool removeFriend(User friend) {
            bool ans = false;
            if (friend != null) {
                ans = friends.Remove(friend.getUserName());
            }
            return ans;
        }

        public bool removeFriend(string friendName)
        {
            bool ans = false;
            if (friendName != null)
            {
                ans = friends.Remove(friendName);
            }
            return ans;
        }

        public string getPassword()
        {
            return this.password;
        }

        public DateTime getCreationTime()
        {
            return this.creationTime;
        }

        public void setCreationTime(DateTime creationTime)
        {
            this.creationTime = creationTime;
        }
    }
}
